<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RenuwalorderApiController extends AbstractRestfulController
{
    public function getList()
    {
    }
    public function get($user_id)
    {	
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$explodeId=explode('-',$user_id);
		$user_id=$explodeId[0];
		$totalOrders = $userMedicineOrderTable->autorenuwalorders($user_id);
		if($totalOrders->count()){
			return new JsonModel(array(
				'value'				=>	1,
				'result'		=> json_encode($totalOrders->toArray()),
			));
		}else{
			return new JsonModel(array(
				'value'			=>	0,
			));
		}
    }
    public function create($replay)
    { 
		$data=array();
		header('Access-Control-Allow-Origin: *');
		$ComplaintRelpiesTable=$this->getServiceLocator()->get('Models\Model\ComplaintRelpiesFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$orderDeliveryTable=$this->getServiceLocator()->get('Models\Model\OrderDeliveryDetailsFactory');
		$data['shop_id']=$replay['complaint_relpier_id'];
		$data['reply_text']=$replay['reply_text'];
		$totalOrders = $ComplaintRelpiesTable->addReplyToComplaints($replay['complaint_id'],$data);
		$getreplyComplaintuserId=$orderDeliveryTable->getreplyComplaintuserId($replay['tracking_id'])->toArray();
		if(count($getreplyComplaintuserId)!=0){
			$sendcomplaint=$notificationTable->sendAdminComplaint($replay,'3','0',$replay['shopId'],'0','1');
			$sendcomplaint=$notificationTable->sendReplyShopComplaint($replay,'3','0',$replay['shopId'],'0','2',$getreplyComplaintuserId[0]['user_id']);
		}
		return new JsonModel(array(
			'status'			=>	'success',
		));
    }
    public function update($order_id,$order)
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$cancelautorenewal = $userMedicineOrderTable->changeAutoRenewal($order_id,$order);
		$sendNotification = $notificationTable->CancelledRenewalOrderNot($order_id,$order,'2','0','1',$order['user_id']);
			return new JsonModel(array(
				'status'			=>	'success',
				'value'			    =>	1,
			));
    }
    public function delete($id)
    {
       
    }
}